<!DOCTYPE html>
<html lang="en" style="background:#fff;">
<head>

<base href="${basePath}">
	 <#include "common/top.html"/>
	<link type="text/css" rel="stylesheet" href="${basePath}plugins/zTree/3.5.1/zTreeStyle/zTreeStyle.css"/>
	<script type="text/javascript" src="${basePath}plugins/zTree/3.5.1/jquery.ztree.core.js"></script>
	<script type="text/javascript" src="${basePath}plugins/zTree/3.5.1/jquery.ztree.excheck.js"></script>
</head>
<style>
	.layui-form-item-dept {
		width: 100%;
		margin: 10px 0 0 33px;
		overflow: auto;
	}
</style>
<body style="background:#fff;height: auto;">
	<div class="layui-elem-field" style="overflow: auto;width: 40%;float: left;height: 286px;margin-left: 16px;margin-top: 10px;">
		<ul id="tree" class="ztree"></ul>
	</div>
	<form class="layui-form layui-form-pamel" style="float:left;" modelAttribute="dept" name="form1" id="form1"  method="post">

		<!--<div class="layui-form-item-dept">
			<div class="layui-form-item">
				<label class="layui-form-label"><span style="color: red;">*</span>部门编号：</label>
				<div class="layui-input-inline">
					<input class="layui-input" type="number" name="deptNo" id="deptNo" placeholder="请输入部门编号" value="${dept.deptNo}"  title="部门编号"/>
				</div>
			</div>-->
		<div class="layui-form-item">
			<label class="layui-form-label"><span style="color: red;">*</span>部门名称：</label>
			<div class="layui-input-inline">
			<input class="layui-input" type="text" name="deptName" id="deptName" placeholder="请输入部门名称" value="${dept.deptName}"  title="部门名称"/>
			</div>
		  </div>
		<div class="layui-form-item">
			<label class="layui-form-label">上级部门：</label>
			<div class="layui-input-inline">
				<input class="layui-input" type="hidden" name="superDeptId" id="parentId" placeholder="上级部门" value="${dept.superDeptId}"  title="上级部门"/>
				<input class="layui-input" type="text" readonly name="parentName" id="parentName" placeholder="上级部门" value="${dept.parentName}"  title="上级部门"/>
			</div>
		</div>
		<div class="layui-form-item" style="display: none">
			<label class="layui-form-label"><span style="color: red;">*</span>部门ID：</label>
			<div class="layui-input-inline">
				<input class="layui-input" type="text" name="deptId" id="deptId" placeholder="请输入部门ID" value="${dept.deptId}"  title="部门ID"/>
			</div>
		</div>

		</div>
	</form>
</body>
<script type="text/javascript">
	var zTree;
	$(document).ready(function(){
		var id =parseInt($("#deptId").val());
		if(!isNaN(id)){
			$("#deptId").attr("readonly",true );
		}
      /*  var NO =parseInt($("#deptNo").val());
		if(!isNaN(NO)){
			$("#deptNo").attr("readonly",true );
		}*/
		var zn = '${zTreeNodes}';
        zn=zn.replace(/&quot;/g,'"');//转换后台返回的&quot;
		var setting = {
			data: {
				key: {
					title: "dept"
				},
				simpleData: {
					enable: true,
					idKey: "id",
					pIdKey: "pId",
					rootPId: 0
				}
			},
			callback:{
				onClick: zTreeOnClick
			}
		};
		var zNodes = eval(zn);
		zTree = $.fn.zTree.init($("#tree"), setting, zNodes);
	});
	function zTreeOnClick(event, treeId, treeNode) {
		$("#parentId").val(treeNode.id);
		$("#parentName").val(treeNode.name);
	}
	//保存
	function save(){
		if(checkIsNull("deptName","请输入部门名称！")){
			return;
		}
/*if(checkIsNull("deptNo","请输入部门编号！")){
			return;
		}*/

	    	
	   /*
		  if(checkIsNull("deptId","请输入部门ID！")){
		   	 return;
		    }
		*/

        $.ajax({
			url: '${basePath}merchant/dept/saveDept',
			data: $("#form1").serialize(),
			type: "POST",
			success: function(data){
				if (data.status == 'success') {
					parent.layer.alert(data.msg,function(index){
						var index1 = parent.layer.getFrameIndex(window.name); //获取窗口索引
						parent.layer.close(index1);
						parent.layer.close(index);
					});
				}else{
					parent.layer.alert(data.msg);
				}
        	}
        });
    }
	function save1(){
		if(checkIsNull("deptName","请输入部门名称！")){
			return;
		}
		if(checkIsNull("deptId","请输入部门ID！")){
			return;
		}

		$.ajax({
			url: '${basePath}merchant/dept/UpdateDept.do',
			data: $("#form1").serialize(),
			type: "POST",
			success: function(data){
				if (data.status == 'success') {
					parent.layer.alert(data.msg,function(index){
						var index1 = parent.layer.getFrameIndex(window.name); //获取窗口索引
						parent.layer.close(index1);
						parent.layer.close(index);
					});
				}else{
					parent.layer.alert(data.msg);
				}
			}
		});
	}
</script>
</body>
</html>